package v1

import (
	"zimuzu_cvn_web_api/config"
	"github.com/gin-gonic/gin"
	"zimuzu_cvn_web_api/service"
	"zimuzu_cvn_web_api/router/api"
	"zimuzu_cvn_web_api/pkg/errno"
	"github.com/pkg/errors"
	"github.com/gin-gonic/gin/binding"
)

type AnnouncementAPI struct {
}

func (index AnnouncementAPI) Name() string {
	return "announcemen API"
}

func (index AnnouncementAPI) Bind() {
	announcementAPI := config.C.Router.Group("/v1/announcement")
	{
		announcementAPI.GET("list", list)
	}
}


type listRequestParams struct{
	Page int `form:"page" json:"page"`
	Per int  `form:"per" json:"per"`
}
//公告列表
func list(c *gin.Context){
	var params listRequestParams
	err := c.ShouldBindWith(&params, binding.Query)
	if err != nil {
		api.SendResponse(c, err, nil)
		return
	}

	announcementList, err := service.GetAnnouncement(params.Page , params.Per)
	if err != nil{
		api.SendResponse(c, errors.New("获取公告列表失败"), announcementList)
		return
	}

	api.SendResponse(c, errno.OK, announcementList)
	return
}



